Namespacing everything to /UVa.
[and.git] / UVa / 11843 - Guessing Game / 11843.2.cpp
blobb14ff9f1bd4fe10ff4ca06a1b73d04638f33c307
1 // Accepted
2 using namespace std;
3 #include <algorithm>
4 #include <iostream>
5 #include <iterator>
6 #include <numeric>
7 #include <sstream>
8 #include <fstream>
9 #include <cassert>
10 #include <climits>
11 #include <cstdlib>
12 #include <cstring>
13 #include <string>
14 #include <cstdio>
15 #include <vector>
16 #include <cmath>
17 #include <queue>
18 #include <deque>
19 #include <stack>
20 #include <list>
21 #include <map>
22 #include <set>
24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 int memo[1005][25];
30 int f(int n, int s) {
31 if (n == 0) return 0;
32 if (n == 1) return 1;
33 if (s == 1) return n;
35 if (memo[n][s] != -1) return memo[n][s];
37 int best = 1<<28;
38 for (int i = 0; i < n; ++i) {
39 int option = 1 + max( f(i, s-1), f(n-i-1, s) );
40 best = min(best, option);
42 return memo[n][s] = best;
45 int main(){
46 int C;
47 cin >> C;
48 memset(memo, -1, sizeof memo);
49 while (C--) {
50 int n, s;
51 cin >> n >> s;
52 assert(s > 0 and n > 0);
53 int ans = f(n, s);
54 printf("%d\n", ans);
56 return 0;